package com.example.dynamicschedule.controller;


import com.alibaba.fastjson.JSON;
import com.example.dynamicschedule.base.ResultDTO;
import com.example.dynamicschedule.service.CkFeedBackConfigService;
import com.example.dynamicschedule.service.PeopleCallService;
import com.example.dynamicschedule.service.ScheduleJobService;
import com.example.dynamicschedule.task.*;
import com.example.dynamicschedule.utils.FileDownloadUtil;
import com.example.dynamicschedule.utils.ResultUtils;
import com.github.pagehelper.PageInfo;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/job")
public class ScheduleController {


    @Autowired
    private ScheduleJobService scheduleJobService;
    @Autowired
    private DataRecoveryTask dataRecoveryTask;

    @Autowired
    private DownLoadFileTask downLoadFileTask;
    @Autowired
    private ScanningCleaningDataTask scanningCleaningDataTask;
    @Autowired
    private UploadFileTask uploadFileTask;
    @Autowired
    private CreditScanningCleaningDataTask creditScanningCleaningDataTask;
    @Autowired
    private CreditDataRecoveryTask creditDataRecoveryTask;
    @Autowired
    private CreditDownLoadFileTask creditDownLoadFileTask;
    static Logger log = Logger.getLogger(ScheduleController.class);
    @Autowired
    private WuMethodReceiveData wuMethodReceiveData;
    @Autowired
    private CreditOutcompanyCommissionTask creditOutcompanyCommissionTask;
    @Autowired
    private CreditOutcompanyRegressionRateTask creditOutcompanyRegressionRateTask;
    @Autowired
    private CreditOutcompanyCommissionSumTask creditOutcompanyCommissionSumTask;

    /**
     * 获取listLog
     * @return
     */
    @GetMapping("/listLog")
    public ResultDTO List(@RequestParam Map<Object,Object>params,HttpServletRequest request) {
        log.info("获取定时任务列表开始-----------参数为"+JSON.toJSONString(params));
        ResultDTO resultDTO=null;
        try {
            PageInfo scheduleJobs= scheduleJobService.selectList(params);
            resultDTO= ResultUtils.getSuccess(scheduleJobs);





        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

        }finally {
            log.info("获取定时任务列表结束----------结果为"+ JSON.toJSONString(resultDTO));
            return resultDTO;
        }
    }
    /**
     * 网贷三方下载
     * @param request
     * @return
     */
    @RequestMapping("/downLoadFile")
    public ResultDTO DownLoadFile(HttpServletRequest request) {
        log.info("获取三方下载开始");
        ResultDTO resultDTO = null;
        try {
            downLoadFileTask.DownLoadFileTask();
            resultDTO = ResultUtils.getSuccess(null);


        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;
          //  resultDTO=  ResultUtils.getSuccess(null);
        }finally {
            return resultDTO;
        }
    }
    /**
     * 网贷大数据清洗规则执行
     * @param request
     * @return
     */
    @RequestMapping("/scanningCleaningData")
    public ResultDTO ScanningCleaningData(HttpServletRequest request) {
        log.info("获取大数据清洗规则执行开始");
        ResultDTO resultDTO = null;

        try {
            scanningCleaningDataTask.ScanningCleaningDataTask();
            resultDTO = ResultUtils.getSuccess(null);



        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

         //   resultDTO=  ResultUtils.getSuccess(null);
        }finally {
            return resultDTO;
        }
    }
    /**
     * 网贷三方上传执行
     * @param request
     * @return
     */
    @RequestMapping("/uploadFile")
    public ResultDTO uploadFile(HttpServletRequest request) {
        log.info("获取三方上传执行开始");
        ResultDTO resultDTO = null;
        try {
            uploadFileTask.UploadFileTask();
            resultDTO = ResultUtils.getSuccess(null);
        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

          //  resultDTO=  ResultUtils.getSuccess(null);

        }finally {
            return resultDTO;
        }
    }
    /**
     * 网贷大数据回收执行
     * @param request
     * @return
     */
    @RequestMapping("/dataRecovery")
    public ResultDTO DataRecovery(HttpServletRequest request) {
        log.info("获取大数据回收执行开始");
        ResultDTO resultDTO = null;
        try {
            dataRecoveryTask.DataRecoveryTask();
            resultDTO = ResultUtils.getSuccess(null);



        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

           // resultDTO=  ResultUtils.getSuccess(null);

        }finally {
            return resultDTO;
        }
    }
    /**
     * 信贷大数据清洗执行
     * @param request
     * @return
     */
    @RequestMapping("/CreditScanningCleaningData")
    public ResultDTO CreditScanningCleaningData(HttpServletRequest request) {
        log.info("获取信贷大数据清洗任务执行开始");
        ResultDTO resultDTO = null;
        try {
            creditScanningCleaningDataTask.CreditScanningCleaningDataTask();
            resultDTO = ResultUtils.getSuccess(null);


        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

        }finally {
            log.info("获取信贷大数据清洗任务执行结束");
            return resultDTO;
        }
    }
    /**
     * 信贷大数据回收执行
     * @param request
     * @return
     */
    @RequestMapping("/CreditDataRecovery")
    public ResultDTO CreditDataRecovery(HttpServletRequest request) {
        log.info("获取大数据回收执行开始");
        ResultDTO resultDTO = null;
        try {
            creditDataRecoveryTask.CreditDataRecoveryTask();
            resultDTO = ResultUtils.getSuccess(null);


        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

        }finally {
            log.info("获取大数据回收执行结束");
            return resultDTO;
        }
    }
    /**
     * 信贷下载三方数据
     * @param request
     * @return
     */
    @RequestMapping("/CreditDownLoadFile")
    public ResultDTO CreditDownLoadFile(HttpServletRequest request) {
        log.info("获取信贷下载三方数据开始");
        ResultDTO resultDTO = null;
        try {
            creditDownLoadFileTask.CreditDownLoadFileTask();
            resultDTO = ResultUtils.getSuccess(null);
        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

        }finally {
            log.info("获取信贷下载三方数据结束");
            return resultDTO;
        }
    }
    /**
     * 计算佣金(佣金比率和固定代理类)
     * @param request
     * @return
     */
    @RequestMapping("/CreditOutcompanyCommission")
    public ResultDTO CreditOutcompanyCommissionTask(HttpServletRequest request) {
        log.info("计算佣金开始");
        ResultDTO resultDTO = null;
        try {
            creditOutcompanyCommissionTask.CreditOutcompanyCommissionTask();
            resultDTO = ResultUtils.getSuccess(null);




        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

        }finally {
            log.info("计算佣金结束");
            return resultDTO;
        }
    }
   /**
     * 计算回退率
     * @param request
     * @return
     */
    @RequestMapping("/CreditOutcompanyRegressionRate")
    public ResultDTO CreditOutcompanyRegressionRateTask(HttpServletRequest request) {
        log.info("计算回退率开始");
        ResultDTO resultDTO = null;
        try {
            creditOutcompanyRegressionRateTask.CreditOutcompanyRegressionRateTask();
            resultDTO = ResultUtils.getSuccess(null);






        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

        }finally {
            log.info("计算回退率结束");
            return resultDTO;
        }
    }
    /**
     * 每月计算总代理费用和佣金费用
     * @param request
     * @return
     */
    @RequestMapping("/CreditOutcompanyCommissionSum")
    public ResultDTO CreditOutcompanyCommissionSumTask(HttpServletRequest request) {
        log.info("每月计算总代理费用和佣金费用开始");
        ResultDTO resultDTO = null;
        try {
            creditOutcompanyCommissionSumTask.CreditOutcompanyCommissionSumTask();
            resultDTO = ResultUtils.getSuccess(null);


        } catch (Exception e) {
            resultDTO   = ResultUtils.getFail("服务错误");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            int param=(int)(Math.random()*900)+100;

        }finally {
            log.info("每月计算总代理费用和佣金费用结束");
            return resultDTO;
        }
    }
    @RequestMapping("/test")
    public void test() throws Exception{
    /* String customerJson=  fileDownloadUtil.readESBJsonFile("M:\\0c9aadf24a7b4de0911fdacc165ce00c.json");
        Map<String, CkFeedbackConfigTable> feedBackConfigMap = ckFeedBackConfigService.selectList();
        //保存人工json数据
        peopleCallService.peopleCallService(customerJson,feedBackConfigMap);*/
      //oneMethodReceiveData.receiveOneData();
        wuMethodReceiveData.updateWuOutData();
    }
}


